// src/main/java/org/zachary/creditbusiness/hotel/service/impl/HotelServiceImpl.java
package org.zachary.creditbusiness.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.zachary.creditbusiness.hotel.controller.dto.HotelFilterCriteria;
import org.zachary.creditbusiness.hotel.entity.Hotel;
import org.zachary.creditbusiness.hotel.mapper.HotelMapper;
import org.zachary.creditbusiness.hotel.service.HotelService;

import java.math.BigDecimal;
import java.util.List;

@Service
public class HotelServiceImpl extends ServiceImpl<HotelMapper, Hotel> implements HotelService {

    @Override
    public List<Hotel> filterHotels(HotelFilterCriteria c) {
        QueryWrapper<Hotel> qw = new QueryWrapper<>();
        if (c.getMinScore() != null) {
            qw.ge("score", c.getMinScore());
        }
        if (StringUtils.isNotBlank(c.getLocation())) {
            qw.and(w -> w.like("location", c.getLocation())
                    .or().like("nearby", c.getLocation()));
        }
        BigDecimal minP = c.getMinPrice(), maxP = c.getMaxPrice();
        if (minP != null && maxP != null) {
            qw.between("price", minP, maxP);
        } else if (minP != null) {
            qw.ge("price", minP);
        } else if (maxP != null) {
            qw.le("price", maxP);
        }
        return baseMapper.selectList(qw);
    }

    @Override
    public List<Hotel> findHotelsByName(String name) {
        QueryWrapper<Hotel> qw = new QueryWrapper<>();
        if (StringUtils.isBlank(name)) {
            // 名称为空，返回全部
            return baseMapper.selectList(null);
        }
        // 精确匹配 hotel_name
        qw.eq("hotel_name", name);
        return baseMapper.selectList(qw);
    }


}